package com.rz.htk.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rz.core.exception.GlobalException;
import com.rz.htk.order.entity.Pdf;
import com.rz.htk.order.entity.Sender;
import com.rz.htk.order.entity.vo.OrderDeleteParam;
import com.rz.htk.order.mapper.PdfMapper;
import com.rz.htk.order.mapper.SenderMapper;
import com.rz.htk.order.service.PdfService;
import com.rz.htk.order.service.SenderService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class PfdServiceImpl extends ServiceImpl<PdfMapper,Pdf> implements PdfService{

    @Transactional
    public boolean savePdf(Pdf pdf){

        boolean isOk = this.saveOrUpdate(pdf);
        if (!isOk) {
            throw new GlobalException("pdf保存失败！");
        }
        return isOk;
    }

    @Override
    public List<Pdf> getPdfByOrderIds(List<Integer> orderIds) {
        QueryWrapper<Pdf> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("order_id", orderIds);
        return list(queryWrapper);
    }

    @Override
    public List<Pdf> getAfterCodeByOrderIds(List<Integer> orderIds) {
        QueryWrapper<Pdf> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("order_id, after_code");
        queryWrapper.in("order_id", orderIds);
        return list(queryWrapper);
    }

    public List<Pdf> getPdfBycode(String code){
        QueryWrapper<Pdf> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("commodity_code", code);
        return list(queryWrapper);
    }
}

